package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yl.auth.model.entity.JiaShu;
import com.yl.auth.model.entity.QianZaiKeHu;
import com.yl.auth.model.entity.ZiXun;
import com.yl.auth.service.JiaShuService;
import com.yl.auth.service.QianZaiKeHuService;
import com.yl.auth.service.ZiXunService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author L
 * @since 2023-06-17
 */
@Api(tags = "市场销售-咨询登记")
@RestController
@RequestMapping("/admin/yanglao/zixun")
public class ZiXunController {
    @Resource
    private ZiXunService ziXunService;
    @Resource
    private QianZaiKeHuService qianZaiKeHuService;
    @Resource
    private JiaShuService jiaShuService;

    @ApiOperation(value = "根据潜在客户id查询咨询登记")
    @GetMapping("/findAll/{id}")
    public Result findAll(@PathVariable Integer id){
        //根据潜在客户外键查询该潜在客户咨询登记的信息
        LambdaQueryWrapper<ZiXun> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ZiXun::getQid,id);
        lambdaQueryWrapper.orderByDesc(ZiXun::getId);
        List<ZiXun> list = ziXunService.list(lambdaQueryWrapper);
        return Result.ok(list);
    }


    @ApiOperation(value = "新增该潜在用户的咨询登记信息")
    @PostMapping("/save/{id}")
    public Result save(@PathVariable Integer id,@RequestBody ZiXun seek){
        seek.setQid(id);
        seek.setCreateDate(LocalDateTime.now());
        ziXunService.save(seek);
        return Result.ok();
    }

    @ApiOperation("根据Id查询指定咨询登记信息")
    @GetMapping("/getSeekById/{id}")
    public Result getSeekById(@PathVariable Integer id){
        ZiXun ziXun = ziXunService.getById(id);
        return Result.ok(ziXun);
    }

    @ApiOperation("修改咨询登记信息")
    @PostMapping("/updateSeek")
    public Result updateSeek(@RequestBody ZiXun ziXun){
        ziXunService.updateById(ziXun);
        return Result.ok();
    }


    @ApiOperation("根据Id删除指定咨询信息")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        ziXunService.removeById(id);
        return Result.ok();
    }

}
